<%@ page import="java.sql.Connection" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%!
    private ThreadLocal<Connection> _db_conn = new ThreadLocal();
    //Connection _db_conn;

    private void _db_init() {

    }

    /**
     * 取 connection
     * @return
     * @throws Exception
     */
    private Connection _db_getConnection() throws Exception {
        Context initContext = new InitialContext();
        Context envContext = (Context) initContext.lookup("java:/comp/env");
        DataSource ds = (DataSource) envContext.lookup("jdbc/oracle");
        Connection conn = ds.getConnection();
        return conn;
    }

    /**
     * 销毁 connection
     * @param conn
     * @param ps
     * @param rs
     * @throws SQLException
     */
    private void _db_destory(Connection conn, PreparedStatement ps, ResultSet rs) throws SQLException {
        if (rs != null) {
            rs.close();
            rs = null;
        }
        if (ps != null) {
            ps.close();
            ps = null;
        }
        if (conn != null) {
            conn.close();
            conn = null;
        }
    }
%>